package com.hengyue.system.domain.entity;

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.hengyue.common.core.entity.BaseEntity;
import com.hengyue.common.core.entity.CoreBaseDataEntity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.Set;


@Getter
@Setter
@NoArgsConstructor
@Entity
public class SysUser extends BaseEntity {

    @JsonSerialize(using = ToStringSerializer.class)
    @GeneratedValue(generator = "SnowIdGenerator")
    @GenericGenerator(type = com.hengyue.common.utils.SnowIdGenerator.class, name = "SnowIdGenerator")
    @Id
    private Long id;

    @Column(unique = true)
    private String name;

    /*@NotBlank*/
    //@ApiModelProperty(value = "用户昵称")
    private String nickName;


    //@NotBlank
    //@ApiModelProperty(value = "电话号码")
    private String phoneNumber;

    //@ApiModelProperty(value = "用户性别")
    private String gender;

    //@ApiModelProperty(value = "头像真实名称", hidden = true)
    private String avatarName;

    //@ApiModelProperty(value = "头像存储的路径", hidden = true)
    private String avatarPath;

    //@ApiModelProperty(value = "密码")
    //@JsonIgnore
    private String password;

    //@NotNull
    //@ApiModelProperty(value = "是否启用")
    private Boolean enabled;

 /*   @ManyToOne(fetch = FetchType.LAZY)
    @JsonIgnore
    private SysDept dept;*/

    /**
     * 删除标志（0代表存在 2代表删除）
     */
    private String delFlag = "0";

    private String status;

    /**
     * 最后登录IP
     */
    private String loginIp;


    private String email;

    /**
     * 最后登录时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime loginDate;

    @JsonIgnore
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(
            name = "user_role", // 中间表的名称
            joinColumns = @JoinColumn(name = "user_id"), // 当前实体在中间表中的外键列名
            inverseJoinColumns = @JoinColumn(name = "role_id") // 关联实体在中间表中的外键列名
    )
    private Set<SysRole> sysRoles = new HashSet<>();


}


